﻿<?php
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act))
	{
		if (empty($iReason) || empty($vContent) || empty($iOwner) 
			|| empty($iStatus)){
			echo "<script>alert('Some content must be filled in data!!');window.history.go(-1);</script>";
			die("Some content must be filled in data!");
		}
		
		if(empty($iRC)) $iRC='NA';
		if(empty($iPurpose) ) $iPurpose='NA';
		if(empty($iScheme)) $iScheme='NA';
		if(empty($iFailrate)) $iFailrate='NA';

		if ($act == 'add')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$db = new mysql();
			$sql="INSERT INTO `validate_issues` (`val_reason`, `val_purpose`, `val_scheme`, `val_failrate`, `val_content`, 
				`val_owner`, `val_duty`, `val_rootcause`, `val_status`) values('".htmlentities($iReason,ENT_QUOTES)."', '".htmlentities($iPurpose,ENT_QUOTES)."', 
					'".htmlentities($iScheme,ENT_QUOTES)."', '".htmlentities($iFailrate,ENT_QUOTES)."', '"
				.htmlentities($vContent,ENT_QUOTES)."', '".htmlentities($iOwner,ENT_QUOTES)."', '".htmlentities($iDuty,ENT_QUOTES)."', '".htmlentities($iRC,ENT_QUOTES)."', '".htmlentities($iStatus,ENT_QUOTES)."')";
			$db->query($sql);
			$db->close();
			echo "<script>alert('数据添加完成!');window.opener.location.reload();window.close();</script>";
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script>
	$(function(){
		$("#addbtn").click(function(){
			if ($("#iReason").val() == ""){
				alert("问题描述没有填写！");
				return false;
			}

			if ($("#iRC").val() == ""){
				alert("问题结论没有填写！");
				return false;
			}

			if ($("#iPurpose").val() == ""){
				alert("短期对策没有填写！");
				return false;
			}

			if ($("#iScheme").val() == ""){
				alert("长期对策没有填写！");
				return false;
			}

			if ($("#iFailrate").val() == ""){
				alert("不良状况没有填写！");
				return false;
			}			

			if ($("#iDuty").val() == ""){
				alert("责任单位没有填写！");
				return false;
			}
		});
	});
</script>

<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>添加问题点</title>
</head>
<body class="background">
<?
	include "admin_top.php";
?>
<div class="container white-background pagecontent">
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">添加问题点</h3>
    </div>
    <div class="panel-body">
	<form action="add_issue.php?act=add" method="post">
	<div class="input-group">
		<span class="input-group-addon">问题描述:</span>
		<input name="iReason" id='iReason' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">问题结论:</span>
		<input name="iRC" id='iRC' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">短期对策:</span>
		<input name="iPurpose" id='iPurpose' class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">长期对策:</span>
		<input name="iScheme" id='iScheme' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">不良状况:</span>
		<input name="iFailrate" id='iFailrate' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">分析人员:</span>
		<input name="iOwner" type="text" readonly="readonly" value=<? echo $_SESSION['logchnname']; ?> class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">责任单位:</span>
		<input name="iDuty" id='iDuty' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">问题状态:</span>
		<select name="iStatus" id="iStatus" class="form-control">
			<option value="Open">Open</option>
			<option value="Tracking">Tracking</option>
			<option value="Close">Close</option>
		</select>
	</div>
<div>
分析步骤:<br />
<textarea name="vContent" rows="12" cols="80" class="xheditor {tools:'mfull',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:280px; no-repeat right bottom fixed">
</textarea>
</div>
<div><input class="btn btn-success btn-primary" name="submit" value="提交" type="submit" id='addbtn'>
<input class="btn btn-danger" name="reset" value="重写" type="reset"></div>
</form>
</div>
</div>
</div>
<?
include '../bottom.php';
?>
</body>
</html>
